package com.booksystem.campuslibrarymanagementsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.booksystem.campuslibrarymanagementsystem.commen.request.userquest.BookBorrowrequst.Approval;
import com.booksystem.campuslibrarymanagementsystem.commen.request.userquest.Renewalapprovalrequest.Renewalapproval;
import com.booksystem.campuslibrarymanagementsystem.commen.result.userresuilt.ApprovalList;
import com.booksystem.campuslibrarymanagementsystem.commen.result.userresuilt.RenewalTable;
import com.booksystem.campuslibrarymanagementsystem.entity.BorrowApprovalsTable;
import com.booksystem.campuslibrarymanagementsystem.entity.RenewalapprovalTable;
import com.booksystem.campuslibrarymanagementsystem.entity.ReservationTable;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface RenewalapprovalTableMapper extends BaseMapper<RenewalapprovalTable> {
    //进行续借
    @Insert("INSERT INTO renewalapproval_table (bookid, renewdate,expirationdate, approvalstate,cause,account) VALUES (#{bookid}, #{renewdate},#{expirationdate},#{approvalstate},#{cause}, #{account})")
    int add(RenewalapprovalTable hh);

    //通过状态是否通过查看列表
    @Select("select * from renewalapproval_table where account = #{account}  and approvalstate = #{approvalstate}")
    List<RenewalTable> liststatus(String account, String approvalstate );

    //判断是否重复续借
    @Select("SELECT * \n" +
            "FROM renewalapproval_table \n" +
            "WHERE account = #{account} AND bookid = #{bookid}")
    List<RenewalapprovalTable>  existsByAccountAndBookidi(String account, int bookid);

    //该账户查询所有借阅列表
    @Select("select * from renewalapproval_table where account = #{account}")
    List<RenewalTable> selectByaccount(@Param("account") String account);

    //删除该账户的借阅记录
    @Delete("DELETE FROM renewalapproval_table WHERE account = #{account} AND approvalid = #{approvalid}")
    int deleteByAccountAndBookid(@Param("account") String account, @Param("approvalid") int approvalid);
    //通过账户id查询借阅记录，获得该账户借阅记录

    //通过借阅审批成功，更新借阅审批表的该审批审批的状态，时间和日期
    @Update("UPDATE renewalapproval_table SET approvaldate = #{approvalTime}, approvalstate = '通过' WHERE account = #{account} And bookid = #{bookid}")
    void onapproval(@Param("account") String account, @Param("approvalTime") LocalDate approvalTime , @Param("bookid") String bookid,@Param("account") String Approvalstate);
    //通过借阅审批失败，更新借阅审批表的该审批审批的状态，时间和日期
    @Update("UPDATE renewalapproval_table SET approvaldate = #{approvalTime}, approvalstate = '通过' WHERE account = #{account} And bookid = #{bookid}")
    void unapproval(@Param("account") String account, @Param("approvalTime") LocalDate approvalTime , @Param("bookid") String bookid,@Param("account") String Approvalstate);
    @Select("SELECT * FROM renewalapproval_table\n" +
            "WHERE account =  #{account} ")
    List<RenewalapprovalTable> queryByAccount(String account);

    //    查询账户人员信息
    @Select("select * from renewalapproval_table where approvalstate = #{state} ")
    List<RenewalapprovalTable> querydislist(String approvalstate);

}
